package com.hanamaki.demo01;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

public class FireFoxDriver {

    WebDriver driver;

    @BeforeClass
    public void setup() {
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        driver = new FirefoxDriver();
    }

    @Test
    public void test() throws InterruptedException, MalformedURLException {
        driver.get("https://www.baidu.com");
        WebElement element = driver.findElement(By.xpath("//input[@id='kw']"));
        element.sendKeys("selenium");
        WebElement element1 = driver.findElement(By.xpath("//input[@value='百度一下']"));
        element1.click();

//        强制等待
//        wait(3)
        Thread.sleep(3000);

//        导航栏 对象的 使用
//        通过 浏览器对象 实例化 导航栏对象
        Navigation navigate = driver.navigate();
        navigate.back();

        Thread.sleep(3000);
        navigate.forward();

        Thread.sleep(3000);
        navigate.refresh();

        Thread.sleep(3000);
        String s = new String("https://www.jd.com");
        navigate.to(s);

        Thread.sleep(3000);
        URL url = new URL("https://www.jd.com");
        navigate.to(url);


    }

    @AfterClass
    public void close() {
        driver.close();
    }


}
